<style>
.{{$t|escape:'html'}}_image_button {
  cursor: pointer;
}
table.{{$t|escape:'html'}}_list {
  width: 800px;
  border-left: 1px solid #dddddd;
  border-top: 1px solid #dddddd;
  margin-bottom: 1px;
  font-size: 11px;
}
table.{{$t|escape:'html'}}_list td.border {
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list th {
  text-align: left;
  height: 35px;
  background-color: #eaf2f5;
  padding: 5px 0 5px 10px; 
  border-right: 1px solid #ffffff;
  border-bottom: 1px solid #ffffff;
}
table.{{$t|escape:'html'}}_list tr.drop td {
  padding-left: 0;
  border-right: 0;
  border-bottom: 0;
}
table.{{$t|escape:'html'}}_list tr.hi td {
  padding-left: 10px;
  height: 35px;
  background-color: #ff8000;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.rowodd td {
  padding-left: 10px;
  height: 35px;
  background-color: #eeeeee;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.roweven td {
  padding-left: 10px;
  height: 35px;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.rowodd:hover td {
  background-color: #f4f3b2;
}
table.{{$t|escape:'html'}}_list tr.roweven:hover td {
  background-color: #f4f3b2;
}
</style>

<table id="{{$t|escape:'html'}}_plugins" class="{{$t|escape:'html'}}_list" cellPadding="0" cellSpacing="0">
  <tr>
    <td style="height: 35px;padding-left: 10px;"><input id="{{$t|escape:'html'}}_plugins_select" type="checkbox"></input></td>
    <td class="border" style="padding-left: 10px;border-bottom: 0;" colSpan=4>
      <table>
        <tr>
          <td><select id="{{$t|escape:'html'}}_plugins_actions"><option>{{t escape='html'}}Actions...{{/t}}</option></select></td>
          <td>
            <span id="spanButtonPlaceHolder"></span>
            <input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="display: none; margin-left: 2px; font-size: 8pt; height: 29px;"></input>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <th style="width: 50px;"></th>
    <th style="width: 500px;">{{t escape='html'}}Name{{/t}}</th>
  </tr>
</table>

<script type="text/javascript" src="libs/pozo/common/myutils.js"></script>
<script type="text/javascript" src="libs/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="libs/pozo/common/popup.js"></script>
<script type="text/javascript" src="libs/pozo/myupload/swfupload.js"></script>
<script type="text/javascript" src="libs/pozo/myupload/swfupload.queue.js"></script>
<script type="text/javascript" src="libs/pozo/myupload/myupload.js"></script>
<script src="jsrequest.php?script={{$t|escape:'html'}}" type="text/javascript"></script>
<script type="text/javascript">
  <!--
    if (document.addEventListener) {
      document.addEventListener('DOMContentLoaded', init, false);
    }
    window.onload = init;
    
    var _plugins = JSON.parse('{{$plugins|@json_encode|escape:'javascript'}}');
    var _move = null;
    var _y = 0;
    var _selects = [];
    
    function init() {
      if (!document.getElementById || !document.createElement || !arguments || arguments.callee._loaded) {
        return;
      }
      arguments.callee._loaded = true;
      
      update_plugins_table();
      
      var select, actions;
      select = document.getElementById('{{$t|escape:'html'}}_plugins_select');
      select.onclick = function() {
        for (var idx in  _selects) {
          var obj = _selects[idx];
          if (obj._obj.is_custom == 0) {
            continue;
          }
          obj.checked = this.checked;
        }
      };
      actions = document.getElementById('{{$t|escape:'html'}}_plugins_actions');
      actions.options[actions.options.length] = new Option('Delete');
      actions.onchange = function() {
        if (this.selectedIndex == 1) {
          var deletes = [];
          for (var idx in  _selects) {
            var obj = _selects[idx];
            if (obj.checked) {
              deletes[deletes.length] = obj._obj;
            }
          }
          new RequestUtils()._custom('delete_plugins', JSON.stringify(deletes), function(result, params) {
            for (var idx in  deletes) {
              var obj = deletes[idx];
              MiscUtils.remove(_plugins, obj, null);
            }
            update_plugins_table();
            actions.selectedIndex = 0;
          }, {
            pos : DOMUtils.findPos(this)
          });
        }
      };
      
      new MyUpload('spanButtonPlaceHolder', 'install.php', function() { 
        location.reload();
      }, {
        debug: 0,
        file_queue_limit: 0,
        file_types: '*.zip',
        file_types_description: 'POZO ZIP FILE',
        post_params: {
          action: 'plugin'
        }
      });
    }
    
    function update_plugins_table() {
      var table, tr, td, elm, div, p;
      
      table = document.getElementById('{{$t|escape:'html'}}_plugins');
      DOMUtils.removeTableRows(table, 2);
      if (_plugins.length == 0) {
        tr = table.insertRow(-1);
        tr.className = 'nohover';
        td = tr.insertCell(-1);
        td.className = 'border';
        td.colSpan = 5;
        td.style.padding = '5px 0 5px 10px';
        td.style.height = '35px';
        td.appendChild(document.createTextNode('{{t escape='javascript'}}No Results Found{{/t}}'));
        
      } else {
        _plugins = MiscUtils.sortByOrder(_plugins);
        
        for (var idx in _plugins) {
          var obj = _plugins[idx];
          
          tr = table.insertRow(-1);
          document.body.onmouseup = function(ev) {
            ev = (ev) ? ev : window.event;
            if (!_move) {
              return;
            }
            new RequestUtils()._custom('ezobj', JSON.stringify({ obj: _move, tbl: 'pz_plugin' }), function(result, params) {
              _move = null;
              update_plugins_table();
            }, {
              php: 'custom.php',
              pos : [ev.clientX, ev.clientY]
            });
          };
          
          if (_move) {
            tr.style.cursor = 'move';
          }
          
          if (_move && obj.track_id == _move.track_id) {
            tr.className = 'hi';
          } else {
            tr.className = (idx % 2 == 1) ? 'rowodd' : 'roweven';
          }
          
          td = tr.insertCell(-1);
          elm = document.createElement('input');
          elm.type = 'checkbox';
          elm._obj = obj;
          _selects.push(elm);
          if (obj.is_custom == 0) {
            elm.disabled = true;
          } else {
            elm.disabled = false;
          }
          td.appendChild(elm);
          
          td = tr.insertCell(-1);
          td.appendChild(document.createTextNode(obj.name));
          update_plugins_cell(obj, td);
        }
      }
    }
    
    function update_plugins_cell(plugin, td) {
      if (!_move || plugin.track_id != _move.track_id) {
        td.style.cursor = 'move';
        td._obj = plugin;
        td.onmousedown = function(ev) {
          ev = (ev) ? ev : window.event;
          _move = this._obj;
          update_plugins_table();
          _y = ev.clientY;
        };
        td.onmouseover = function(ev) {
          ev = (ev) ? ev : window.event;
          if (OOBTUtils.move(_move, this._obj, _plugins, (ev.clientY - _y < 0))) {
            _y = ev.clientY;
            update_plugins_table();
          }
        };
      }
    }
  -->
</script>
